<?php

/**
 * home actions.
 *
 * @package    estate
 * @subpackage home
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class homeActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
	$this->step0 = new ApartmanBookingFormStep0();
	
	$this->getUser()->getAttributeHolder()->removeNamespace( 'booking' );
	$this->getUser()->getAttributeHolder()->removeNamespace( 'paypal' );
	
	if ( $request->getMethod() == sfRequest::POST )
	{
	 $this->step0->bind( $this->getRequestParameter( 'booking_step0' ) );
	 if ( $this->step0->isValid() )
	 {
	  foreach( $this->step0->getTaintedValues() as $key => $value )
	  {
	   $this->getUser()->setAttribute( $key, $value, 'booking' );
	  }
	  $this->getUser()->setAttribute( 'step0', "success", "booking" );
	  $this->redirect( 'list/index' );
	 }	 
	}
   
  	$c = new Criteria();
  	$c->setLimit(3);
  	$this->apartman = ApartmanPeer::doSelect($c);
  }
  
  public function executeGetImage()
  {
    header('Content-type: image/png');
    $apartmanId = $this->getRequestParameter( 'id' );
    $apartman = ApartmanPeer::retrieveByPK( $apartmanId );
    $c = new Criteria();
    $c->addAscendingOrderByColumn( jwGalleryPicturePeer::ORDER );
    $picture = current( $apartman->getjwGallery()->getjwGalleryPictures( $c ) );
	$a = new gdImage( sfConfig::get( "sf_root_dir" )."/galleries/".$picture->getjwGallery()->getPath()."/thumbs/300/".$picture->getFileName() );
	$a->show();
    return sfView::NONE;
  }
  
  public function executeGetPriceBadge()
  {
    header('Content-type: image/png');
    $apartmanId = $this->getRequestParameter( 'id' );
    $apartman = ApartmanPeer::retrieveByPK( $apartmanId );   
	$a = new gdImage( "images/starbadge.png" );
	$a->setColor( "#FBBA0025" )->writeTTFText( '875 &#8364;', 12, 44, 'center', 'middle' )->show();
    return sfView::NONE;    
  }
}
